#ifndef FONTS_H
#define FONTS_H

#include <Arduino.h>
#include <stdint.h>

// Font index helper for 5x8 font
static inline int fontIndex(char c) {
    if (c == ' ') return 0;
    if (c >= 'A' && c <= 'Z') return 1 + (c - 'A');
    if (c >= 'a' && c <= 'z') return 1 + (c - 'a'); // Support lowercase as uppercase
    if (c >= '0' && c <= '9') return 27 + (c - '0');
    if (c == '-') return 37;
    if (c == '.') return 38;
    if (c == '!') return 39;
    return 0; // Default to space for unsupported characters
}

// Narrow 5x8 ASCII font (A-Z, a-z->A-Z, 0-9, space, dash, period, exclamation)
static const unsigned char font5x8[][8] = {
    /* space */ {0, 0, 0, 0, 0, 0, 0, 0},
    /* A */ {0x0E, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11, 0x00},
    /* B */ {0x1F, 0x15, 0x15, 0x1B, 0x15, 0x15, 0x1F, 0x00},
    /* C */ {0x1E, 0x11, 0x10, 0x10, 0x10, 0x11, 0x1E, 0x00},
    /* D */ {0x1F, 0x12, 0x12, 0x12, 0x12, 0x12, 0x1F, 0x00},
    /* E */ {0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x1F, 0x00},
    /* F */ {0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x10, 0x00},
    /* G */ {0x1E, 0x10, 0x10, 0x17, 0x11, 0x11, 0x1E, 0x00},
    /* H */ {0x11, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11, 0x00},
    /* I */ {0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x1F, 0x00},
    /* J */ {0x1F, 0x01, 0x01, 0x01, 0x01, 0x11, 0x1E, 0x00},
    /* K */ {0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11, 0x00},
    /* L */ {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x00},
    /* M */ {0x11, 0x1B, 0x15, 0x15, 0x11, 0x11, 0x11, 0x00},
    /* N */ {0x11, 0x19, 0x15, 0x13, 0x11, 0x11, 0x11, 0x00},
    /* O */ {0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E, 0x00},
    /* P */ {0x1E, 0x11, 0x11, 0x1E, 0x10, 0x10, 0x10, 0x00},
    /* Q */ {0x0E, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0D, 0x00},
    /* R */ {0x1E, 0x11, 0x11, 0x1E, 0x14, 0x12, 0x11, 0x00},
    /* S */ {0x0F, 0x10, 0x10, 0x0E, 0x01, 0x01, 0x1E, 0x00},
    /* T */ {0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00},
    /* U */ {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E, 0x00},
    /* V */ {0x11, 0x11, 0x11, 0x11, 0x11, 0x0A, 0x04, 0x00},
    /* W */ {0x11, 0x11, 0x11, 0x15, 0x15, 0x1B, 0x11, 0x00},
    /* X */ {0x11, 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x11, 0x00},
    /* Y */ {0x11, 0x11, 0x11, 0x0E, 0x04, 0x04, 0x04, 0x00},
    /* Z */ {0x1F, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1F, 0x00},
    /* 0 */ {0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E, 0x00},
    /* 1 */ {0x04, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x0E, 0x00},
    /* 2 */ {0x0E, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1F, 0x00},
    /* 3 */ {0x1F, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0E, 0x00},
    /* 4 */ {0x02, 0x06, 0x0A, 0x12, 0x1F, 0x02, 0x02, 0x00},
    /* 5 */ {0x1F, 0x10, 0x1E, 0x01, 0x01, 0x11, 0x0E, 0x00},
    /* 6 */ {0x06, 0x08, 0x10, 0x1E, 0x11, 0x11, 0x0E, 0x00},
    /* 7 */ {0x1F, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08, 0x00},
    /* 8 */ {0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E, 0x00},
    /* 9 */ {0x0E, 0x11, 0x11, 0x0F, 0x01, 0x02, 0x0C, 0x00},
    /* - */ {0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00},
    /* . */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18},
    /* ! */ {0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04, 0x00},
};

#endif // FONTS_H